<script setup lang="ts">
import type { LoginData } from "~/composables/api/auth";
definePageMeta({
  layout: "login",
});

const ruleForm = reactive({
  username: "admin",
  password: "123456",
} as LoginData);

const onLogin = async () => {
  const token = await useLogin(ruleForm);
  if (token) {
    ElMessage.info("登录成功");
    navigateTo("/");
  } else {
    ElMessage.error("登录失败");
  }
};
</script>

<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-header">
        <h1>Paopao Admin</h1>
        <p>欢迎登录管理系统</p>
      </div>

      <el-form :model="ruleForm" class="login-form">
        <el-form-item>
          <el-input
            v-model="ruleForm.username"
            placeholder="请输入用户名"
            size="large"
            prefix-icon="ep:user"
          />
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="ruleForm.password"
            type="password"
            placeholder="请输入密码"
            size="large"
            show-password
            prefix-icon="ep:lock"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            size="large"
            style="width: 100%"
            @click="onLogin"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
  width: 400px;
  padding: 40px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);

  .login-header {
    text-align: center;
    margin-bottom: 30px;

    h1 {
      font-size: 28px;
      font-weight: 600;
      color: #303133;
      margin-bottom: 8px;
    }

    p {
      color: #909399;
      font-size: 14px;
    }
  }
}

.login-form {
  .el-form-item {
    margin-bottom: 20px;
  }
}
</style>
